<?php
  getHeader();
  if (isset($_SESSION['adminPassed']))
  {
	getPanel();
?>
	<ul>
		<li><a href='?p=userAdmin&do=addUser'>新建用户</a></li>
		<li><a href='?p=userAdmin&do=editUser'>用户资料编辑</a></li>
	</ul>
	
<?php 
	$action = isset($_GET['do']) ? $_GET['do'] : "";
	
	switch ($action)
	{
		case 'addUser':
			{
				if (isset($_POST['addUser']))
				{
					$i = addUser($_POST['addUser']);
					if ($i != 'NO')
					{
?>
						<span>新建用户成功</span><br />
						<span>用户密码为: <?php echo $i;?></span>
<?php
					}
					else 
					{
?>
					<span>新建用户失败</span><br />
<?php
					}
				}
				else 
				{
?>
					<form action='?p=userAdmin&do=addUser' method='post'>
						<p>用户名: <input type="text" name="addUser" /></p>
						<p><input type="submit" value="提交" />
					</form>
<?php
				}
			}
			break;
		case 'editUser':
			{
				if (isset($_POST['editDetail']) && isset($_POST['editUser']))
				{
					$person = userProf::getUserByUsername($_POST['editUser']);
					$person->nickName = $_POST['userNickname'];
					$person->sex = $_POST['userSex'];
					$person->email = $_POST['userEmail'];
					$person->college = $_POST['userCollege'];
					$person->pro = $_POST['userPro'];
					$person->grade = $_POST['userGrade'];
					$person->class = $_POST['userClass'];
					$person->tag = $_POST['userTag'];
					$person->introduction = $_POST['userIntroduction'];
					$person->competition = $_POST['competition'];
					if ($person->update())
					{
?>
						<span>修改成功</span><br />
<?php
					}
					else 
					{
?>
						<span>修改失败</span>
<?php
					}
				}
				else if (isset($_POST['editUser']))
				{
					$person = userProf::getUserByUsername($_POST['editUser']);
?>
					<div id="content">
						<div class="tabs headTabs"><span>修改用户信息</span></div>
						<div class="dataList">
							<ul>
								<form action='?p=userAdmin&do=editUser' method='post' id='editProfileForm'>
									<input type="hidden" name="editDetail" value="yes" />
									<input type="hidden" name="editUser" value="<?php echo $_POST['editUser']; ?>">
									<li>昵称: <input type="text" name="userNickname" id="userNickname" value='<?php echo $person->nickName; ?>' /></li>
									<li>性别: <select name="userSex" id="userSex">
										<option value=" " <?php if ($person->sex == "") echo "selected='selected'";?>></option>
										<option value="男" <?php if ($person->sex == "男") echo "selected='selected'";?>>男</option>
										<option value="女" <?php if ($person->sex == "女") echo "selected='selected'";?>>女</option>
											</select>
									</li>
									<li>Email: <input type="text" name="userEmail" id="userEmail" value='<?php echo $person->email;?>' /></li>
									<li>院系: <input type="text" name="userCollege" id="userCollege" 	value='<?php echo $person->college;?>' /></li>
									<li>专业: <input type="text" name="userPro" id="userPro" value='<?php echo $person->pro;?>' /></li>
									<li>年级: <input type="text" name="userGrade" id="userGrade" value='<?php echo $person->grade;?>' /></li>
									<li>班级: <input type="text" name="userClass" id="userClass" value='<?php echo $person->class;?>' /></li>
									<li>个人标签: <input type="text" name="userTag" id="userTag" value='<?php echo $person->tag;?>' /><span>多个标签以半角逗号","分开</span></li>
									<li>个人介绍: <textarea rows="3" cols="20" name="userIntroduction" id="userIntroduction"><?php echo $person->introduction;?></textarea></li>
									<li>参赛经历: <textarea rows="3" cols="20" name="userCompetition" id="userCompetition"><?php echo $person->competition;?></textarea><span>格式为"XX比赛-X等奖-队伍名", 多个比赛以半角逗号","分开</span></li>
									<li><input type="submit" value="提交修改" class="button" /></li>
								</form>
							</ul>
						</div>
					</div>
<?php
				}
				else
				{
?>
					<form action='?p=userAdmin&do=editUser' method='post'>
						用户名: <input type="text" name="editUser" />
						<br /><input type="submit" value="查找" />
					</form>
<?php
				}
			}
		default:
			{
				
			}
	}
	getFooter();
  }
  else
  {
?>
	<span>你无权进行管理操作</span>
<?php
  }
?>